package zhoufu.sz.sanxiao_check.presents;

import javax.inject.Inject;

import zhoufu.sz.sanxiao_check.models.AddFiveInOneModel;
import zhoufu.sz.sanxiao_check.models.BaseModel;
import zhoufu.sz.sanxiao_check.net.BasicRequestRepository;
import zhoufu.sz.sanxiao_check.net.RequestHelper;
import zhoufu.sz.sanxiao_check.ui.contract.AddFiveInOneContract;

public class AddFiveInOnePresenter implements AddFiveInOneContract.Presenter {

    private BasicRequestRepository _requestHelper;


    private AddFiveInOneContract.View view;

    @Inject
    public AddFiveInOnePresenter(BasicRequestRepository _requestHelper) {
        this._requestHelper = _requestHelper;
    }

    public void bindView(AddFiveInOneContract.View view) {
        this.view = view;
    }

    @Override
    public void update(AddFiveInOneModel model) {
        _requestHelper.AddFiveInOne(model, new RequestHelper.RequestCallBack<BaseModel>() {
            @Override
            public void onPullStart() {
                view.pullStart();
            }

            @Override
            public void onPullFailud(Throwable throwable) {
                view.pullFaild();
            }

            @Override
            public void onPullEnd() {
                view.pullEnd();
            }

            @Override
            public void onPullSuccessed(BaseModel model) {
                if (model.isSuccess()) {
                    view.updateSuccese(model);
                } else {
                    view.showToast(model.getErrMsg());
                }
            }
        });
    }

    @Override
    public void loadData(String sid) {
        _requestHelper.GetSupervise(sid, new RequestHelper.RequestCallBack<AddFiveInOneModel>() {
            @Override
            public void onPullStart() {
                view.pullStart();
            }

            @Override
            public void onPullFailud(Throwable throwable) {
                view.pullFaild();
            }

            @Override
            public void onPullEnd() {
                view.pullEnd();
            }

            @Override
            public void onPullSuccessed(AddFiveInOneModel model) {
                if(model.isSuccess()) {
                    if(model.getData()!=null&&!model.getData().isEmpty()) {
                        view.onLoadSuccess(model.getData().get(0));
                    }else {
                        view.onLoadSuccess(model);
                    }
                }else{
                    view.showToast(model.getErrMsg());
                }
            }
        });
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onDestroy() {

    }
}
